<template>
  <div class="es">
    <div class="es-title">
      <div style="font-weight: bold">{{envd.project_name}}</div>
      <div class="state">
        <span></span>
        <span>Active</span>
      </div>
    </div>
    <div class="date">
       - created on {{date}}
    </div>
    <div class="envd-data-item data-s" v-if="language">
      <span class="envd-data-item--subtitle">Language</span>
      <span>{{envd.language}}</span>
    </div>
    <div class="envd-data-item data-s">
      <span class="envd-data-item--subtitle">ContainerID</span>
      <span>{{envd.id}}</span>
    </div>
    <div class="envd-data-item data-s">
      <span class="envd-data-item--subtitle">GPU</span>
      <span>{{Array.isArray(envd.build_metadata?.cuda)? '😥Disabled': '😊Enabled'}}</span>
    </div>
    <div class="data-s">
      <span class="envd-data-item--subtitle">Extensions</span>
      <div class="envd-data-item" v-for="item in envd.extensions" :key="item.type">
        <span class="extension">{{item.type}}</span>
        <span class="extension">{{item.port}}</span>
      </div>
    </div>
    <div class="es-btm">
      <n-button>SSH-Config</n-button>
      <n-button type="error">Shutdown</n-button>
    </div>
  </div>
</template>

<script setup>
import dayjs from 'dayjs'
import { NButton } from 'naive-ui'
import { computed, defineProps, ref } from 'vue'
let props = defineProps(['envd'])
let envd = ref(props.envd)

let date = computed(() => {
  let d = dayjs(envd.created).$d.toString().split(' ')
  return `${d[1]} ${d[2]} ${d[3]}`
})

</script>

<style scoped>
.es {
  --stateColor: #40C057;
  border-radius: 10px;
  padding: 20px;
  border: 1px solid black;
  background-color: #fff;
}
.es-title {
  font-size: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.date {
  font-size: 18px;
}
.state * {
  vertical-align: middle;
  font-size: 22px;
  color: var(--stateColor);
}
.state span:first-child {
  display: inline-block;
  margin-right: 10px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--stateColor);
  animation: spark 2s infinite;
  margin-bottom: 2px;
}
@keyframes spark {
  0% {opacity: 1}
  50% {opacity: 0}
  100% {opacity: 1}
}
.data-s {
  padding-top: 20px;
  font-size: 20px;
}
.envd-data-item {
  display: flex;
  justify-content: space-between;
}
.envd-data-item--subtitle {
  font-weight: bold;
}
.extension {
  padding-top: 20px;
}
.es-btm {
  margin-top: 40px;
  display: flex;
  justify-content: space-between;
}
.es-btm * {
  width: 45%;
  height: 50px;
  border-radius: 10px;
  font-size: 18px;
}
</style>
